package com.project.controller.storeController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.StoreBean;
import com.project.mapper.managerMapper.IManagerMapper;
import com.project.service.storeService.IStoreService;
import com.project.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/store")
public class StoreController {
    @Autowired
    private IStoreService storeService;
    @Autowired
    private IManagerMapper managerMapper;

    @RequestMapping("/add")
    public String add(StoreBean store,Integer managerId,@RequestParam("face") MultipartFile mf) throws Exception {
        String fileName = UploadUtil.upload(mf,"static/html/img");
        store.setImg(fileName);
        storeService.add(store);
        managerMapper.updateStore(managerId,store.getId());
        return "ok";
    }

    @RequestMapping("/updateApply")
    public String updateApply(int id, String remark, String state) {
        storeService.updateApply(id, remark, state);
        return "ok";
    }

    @RequestMapping("/updateBusiness")
    public String updateBusiness(int id, String state) {
        storeService.updateBusiness(id, state);
        return "ok";
    }

    @RequestMapping("/findById")
    public StoreBean findById(int id) {
        return storeService.findById(id);
    }

    @RequestMapping("/findByItem")
    public PageInfo<StoreBean> findByItem(int pageNO, String city, String state) {
        return storeService.findByItem(pageNO, city, state);
    }

    @RequestMapping("/findAll")
    public PageInfo<StoreBean> findAll(int pageNO) {
        return storeService.findAll(pageNO);
    }
}
